/*
 * ESSprintingSalmon.cs
 *
 * Created on January 4, 2008, 1:11 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Windows.Media;
using System.Windows.Shapes;

using HexTD.util;

namespace HexTD.sprite
{
	public class ESSprintingSalmon : EnemySpriteBaseDirectional
	{

		private int energy = 80;
		private int energyMax = 80;
		private long oldHealth;
		private bool sprinting = false;
		private bool recharging = false;
		private float oldSpeed;
		private float oldPower;
		private string infoText = "<h1>Sprinting Salmon</h1>" +
				"<p>" +
				"If a Sprinting Salmon takes damage, it tries to sprint out of harms way." +
				"</p>";

		/** Creates a new instance of ESSprintingSalmon */
		public ESSprintingSalmon()
			: base("Sprinting Salmon", true)
		{
			this.damageColor = COLOR.OTHER;
			this.damageColorAnti = COLOR.OTHER;
		}

		protected override void doInit(Context context, int path, float delay, long health, int price, Size s)
		{
			context.loadSvg("ss", "images\\image2.svg");
			base.doInit(context, path, delay, health, price, s);
			this.oldHealth = health;
			this.oldSpeed = this.speedMaxBase;
			this.oldPower = this.powerBase;
		}

		public override string getInfostring()
		{
			return this.infoText +
					"<p>" + base.getInfostring() + "</p>";
		}

		public override void doTick(int gameTime)
		{
			if (!this.sprinting && !this.recharging)
			{
				if (this.health < this.oldHealth)
				{
					this.sprinting = true;
					this.speedMaxBase = this.oldSpeed * 2;
					this.speedMax *= 2;
					this.powerBase = this.oldPower * 2;
					this.power *= 2;
					this.speed = this.speedMax;
				}
			}
			if (this.recharging)
			{
				this.energy++;
				if (this.energy >= this.energyMax)
				{
					this.recharging = false;
				}
			}
			if (this.sprinting)
			{
				this.energy -= 2;
				if (this.energy <= 0)
				{
					this.sprinting = false;
					this.recharging = true;
					this.speedMaxBase = this.oldSpeed;
					this.powerBase = this.oldPower;
					this.speedMax /= 2;
					this.power /= 2;
					if (this.speedMax > this.speedMaxBase)
					{
						this.speedMax = this.speedMaxBase;
					}
					if (this.power > this.powerBase)
					{
						this.power = this.powerBase;
					}
				}
			}
			base.doTick(gameTime);
			this.oldHealth = this.health;
		}

		public override Color generateColor()
		{
			return Colors.Transparent;
		}

		public override Brush generateStroke()
		{
			return null;
		}

		public override Shape[] generateShapes()
		{
			return null;
		}

		public override string getSvgName()
		{
			return "ss";
		}
	}
}